<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>pyqt5 无边框界面 | Xing's Blog</title><meta name="author" content="xing"><meta name="copyright" content="xing"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="pyqt5 无边框界面">
<meta property="og:type" content="article">
<meta property="og:title" content="pyqt5 无边框界面">
<meta property="og:url" content="https://veryxing.github.io/article/0.html">
<meta property="og:site_name" content="Xing&#39;s Blog">
<meta property="og:description" content="pyqt5 无边框界面">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png">
<meta property="article:published_time" content="2024-10-14T07:20:13.000Z">
<meta property="article:modified_time" content="2024-10-31T15:24:44.015Z">
<meta property="article:author" content="xing">
<meta property="article:tag" content="PyQt">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://veryxing.github.io/article/0.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!true && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        if (name && globalFn[key][name]) return
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.json","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"未找到符合您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":true},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'pyqt5 无边框界面',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-10-31 23:24:44'
}</script><meta name="generator" content="Hexo 7.3.0"><link rel="alternate" href="/atom.xml" title="Xing's Blog" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "/images/2.gif" data-lazy-src="/img/butterfly-icon.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">59</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">55</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/gallery/"><i class="fa-fw fas fa-folder-open"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/shuoshuo/"><i class="fa-fw fas fa-folder-open"></i><span> 说说</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png);"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><span class="site-name">Xing's Blog</span></a><a class="nav-page-title" href="/"><span class="site-name">pyqt5 无边框界面</span></a></span><div id="menus"><div id="search-button"><span class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></span></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/gallery/"><i class="fa-fw fas fa-folder-open"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/shuoshuo/"><i class="fa-fw fas fa-folder-open"></i><span> 说说</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">pyqt5 无边框界面</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-10-14T07:20:13.000Z" title="发表于 2024-10-14 15:20:13">2024-10-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-10-31T15:24:44.015Z" title="更新于 2024-10-31 23:24:44">2024-10-31</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/PyQt/">PyQt</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="pyqt5-无边框界面"><a href="#pyqt5-无边框界面" class="headerlink" title="pyqt5 无边框界面"></a>pyqt5 无边框界面</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> PyQt5.QtWidgets <span class="keyword">import</span> QWidget, QLabel, QPushButton, QVBoxLayout</span><br><span class="line"><span class="keyword">from</span> PyQt5.QtCore <span class="keyword">import</span> Qt, QPoint</span><br><span class="line"><span class="keyword">from</span> PyQt5.QtGui <span class="keyword">import</span> QFont, QCursor</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">QTitleLabel</span>(<span class="title class_ inherited__">QLabel</span>):</span><br><span class="line">    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    新建标题栏标签类</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, *args</span>):</span><br><span class="line">        <span class="built_in">super</span>(QTitleLabel, <span class="variable language_">self</span>).__init__(*args)</span><br><span class="line">        <span class="variable language_">self</span>.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)</span><br><span class="line">        <span class="variable language_">self</span>.setFixedHeight(<span class="number">30</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">QTitleButton</span>(<span class="title class_ inherited__">QPushButton</span>):</span><br><span class="line">    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    新建标题栏按钮类</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, *args</span>):</span><br><span class="line">        <span class="built_in">super</span>(QTitleButton, <span class="variable language_">self</span>).__init__(*args)</span><br><span class="line">        <span class="variable language_">self</span>.setFont(QFont(<span class="string">&quot;Webdings&quot;</span>))  <span class="comment"># 特殊字体以不借助图片实现最小化最大化和关闭按钮</span></span><br><span class="line">        <span class="variable language_">self</span>.setFixedWidth(<span class="number">40</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">QUnFrameWindow</span>(<span class="title class_ inherited__">QWidget</span>):</span><br><span class="line">    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    无边框窗口类</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">super</span>(QUnFrameWindow, <span class="variable language_">self</span>).__init__(<span class="literal">None</span>, Qt.FramelessWindowHint)  <span class="comment"># 设置为顶级窗口，无边框</span></span><br><span class="line">        <span class="variable language_">self</span>._padding = <span class="number">5</span>  <span class="comment"># 设置边界宽度为5</span></span><br><span class="line">        <span class="variable language_">self</span>.initTitleLabel()  <span class="comment"># 安放标题栏标签</span></span><br><span class="line">        <span class="variable language_">self</span>.setWindowTitle = <span class="variable language_">self</span>._setTitleText(<span class="variable language_">self</span>.setWindowTitle)  <span class="comment"># 用装饰器将设置WindowTitle名字函数共享到标题栏标签上</span></span><br><span class="line">        <span class="variable language_">self</span>.setWindowTitle(<span class="string">&quot;UnFrameWindow&quot;</span>)</span><br><span class="line">        <span class="variable language_">self</span>.initLayout()  <span class="comment"># 设置框架布局</span></span><br><span class="line">        <span class="variable language_">self</span>.setMinimumWidth(<span class="number">250</span>)</span><br><span class="line">        <span class="variable language_">self</span>.setMouseTracking(<span class="literal">True</span>)  <span class="comment"># 设置widget鼠标跟踪</span></span><br><span class="line">        <span class="variable language_">self</span>.initDrag()  <span class="comment"># 设置鼠标跟踪判断默认值</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">initDrag</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 设置鼠标跟踪判断扳机默认值</span></span><br><span class="line">        <span class="variable language_">self</span>._move_drag = <span class="literal">False</span></span><br><span class="line">        <span class="variable language_">self</span>._corner_drag = <span class="literal">False</span></span><br><span class="line">        <span class="variable language_">self</span>._bottom_drag = <span class="literal">False</span></span><br><span class="line">        <span class="variable language_">self</span>._right_drag = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">initTitleLabel</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 安放标题栏标签</span></span><br><span class="line">        <span class="variable language_">self</span>._TitleLabel = QTitleLabel(<span class="variable language_">self</span>)</span><br><span class="line">        <span class="variable language_">self</span>._TitleLabel.setMouseTracking(<span class="literal">True</span>)  <span class="comment"># 设置标题栏标签鼠标跟踪（如不设，则标题栏内在widget上层，无法实现跟踪）</span></span><br><span class="line">        <span class="variable language_">self</span>._TitleLabel.setIndent(<span class="number">10</span>)  <span class="comment"># 设置标题栏文本缩进</span></span><br><span class="line">        <span class="variable language_">self</span>._TitleLabel.move(<span class="number">0</span>, <span class="number">0</span>)  <span class="comment"># 标题栏安放到左上角</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">initLayout</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 设置框架布局</span></span><br><span class="line">        <span class="variable language_">self</span>._MainLayout = QVBoxLayout()</span><br><span class="line">        <span class="variable language_">self</span>._MainLayout.setSpacing(<span class="number">0</span>)</span><br><span class="line">        <span class="variable language_">self</span>._MainLayout.addWidget(QLabel(), Qt.AlignLeft)  <span class="comment"># 顶一个QLabel在竖放框架第一行，以免正常内容挤占到标题范围里</span></span><br><span class="line">        <span class="variable language_">self</span>._MainLayout.addStretch()</span><br><span class="line">        <span class="variable language_">self</span>.setLayout(<span class="variable language_">self</span>._MainLayout)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">addLayout</span>(<span class="params">self, QLayout</span>):</span><br><span class="line">        <span class="comment"># 给widget定义一个addLayout函数，以实现往竖放框架的正确内容区内嵌套Layout框架</span></span><br><span class="line">        <span class="variable language_">self</span>._MainLayout.addLayout(QLayout)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_setTitleText</span>(<span class="params">self, func</span>):</span><br><span class="line">        <span class="comment"># 设置标题栏标签的装饰器函数</span></span><br><span class="line">        <span class="keyword">def</span> <span class="title function_">wrapper</span>(<span class="params">*args</span>):</span><br><span class="line">            <span class="variable language_">self</span>._TitleLabel.setText(*args)</span><br><span class="line">            <span class="keyword">return</span> func(*args)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> wrapper</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">setTitleAlignment</span>(<span class="params">self, alignment</span>):</span><br><span class="line">        <span class="comment"># 给widget定义一个setTitleAlignment函数，以实现标题栏标签的对齐方式设定</span></span><br><span class="line">        <span class="variable language_">self</span>._TitleLabel.setAlignment(alignment | Qt.AlignVCenter)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">setCloseButton</span>(<span class="params">self, <span class="built_in">bool</span></span>):</span><br><span class="line">        <span class="comment"># 给widget定义一个setCloseButton函数，为True时设置一个关闭按钮</span></span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">bool</span> == <span class="literal">True</span>:</span><br><span class="line">            <span class="variable language_">self</span>._CloseButton = QTitleButton(<span class="string">b&#x27;\xef\x81\xb2&#x27;</span>.decode(<span class="string">&quot;utf-8&quot;</span>), <span class="variable language_">self</span>)</span><br><span class="line">            <span class="variable language_">self</span>._CloseButton.setObjectName(<span class="string">&quot;CloseButton&quot;</span>)  <span class="comment"># 设置按钮的ObjectName以在qss样式表内定义不同的按钮样式</span></span><br><span class="line">            <span class="variable language_">self</span>._CloseButton.setToolTip(<span class="string">&quot;关闭窗口&quot;</span>)</span><br><span class="line">            <span class="variable language_">self</span>._CloseButton.setMouseTracking(<span class="literal">True</span>)  <span class="comment"># 设置按钮鼠标跟踪（如不设，则按钮在widget上层，无法实现跟踪）</span></span><br><span class="line">            <span class="variable language_">self</span>._CloseButton.setFixedHeight(<span class="variable language_">self</span>._TitleLabel.height())  <span class="comment"># 设置按钮高度为标题栏高度</span></span><br><span class="line">            <span class="variable language_">self</span>._CloseButton.clicked.connect(<span class="variable language_">self</span>.close)  <span class="comment"># 按钮信号连接到关闭窗口的槽函数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">setMinMaxButtons</span>(<span class="params">self, <span class="built_in">bool</span></span>):</span><br><span class="line">        <span class="comment"># 给widget定义一个setMinMaxButtons函数，为True时设置一组最小化最大化按钮</span></span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">bool</span> == <span class="literal">True</span>:</span><br><span class="line">            <span class="variable language_">self</span>._MinimumButton = QTitleButton(<span class="string">b&#x27;\xef\x80\xb0&#x27;</span>.decode(<span class="string">&quot;utf-8&quot;</span>), <span class="variable language_">self</span>)</span><br><span class="line">            <span class="variable language_">self</span>._MinimumButton.setObjectName(<span class="string">&quot;MinMaxButton&quot;</span>)  <span class="comment"># 设置按钮的ObjectName以在qss样式表内定义不同的按钮样式</span></span><br><span class="line">            <span class="variable language_">self</span>._MinimumButton.setToolTip(<span class="string">&quot;最小化&quot;</span>)</span><br><span class="line">            <span class="variable language_">self</span>._MinimumButton.setMouseTracking(<span class="literal">True</span>)  <span class="comment"># 设置按钮鼠标跟踪（如不设，则按钮在widget上层，无法实现跟踪）</span></span><br><span class="line">            <span class="variable language_">self</span>._MinimumButton.setFixedHeight(<span class="variable language_">self</span>._TitleLabel.height())  <span class="comment"># 设置按钮高度为标题栏高度</span></span><br><span class="line">            <span class="variable language_">self</span>._MinimumButton.clicked.connect(<span class="variable language_">self</span>.showMinimized)  <span class="comment"># 按钮信号连接到最小化窗口的槽函数</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton = QTitleButton(<span class="string">b&#x27;\xef\x80\xb1&#x27;</span>.decode(<span class="string">&quot;utf-8&quot;</span>), <span class="variable language_">self</span>)</span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setObjectName(<span class="string">&quot;MinMaxButton&quot;</span>)  <span class="comment"># 设置按钮的ObjectName以在qss样式表内定义不同的按钮样式</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setToolTip(<span class="string">&quot;最大化&quot;</span>)</span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setMouseTracking(<span class="literal">True</span>)  <span class="comment"># 设置按钮鼠标跟踪（如不设，则按钮在widget上层，无法实现跟踪）</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setFixedHeight(<span class="variable language_">self</span>._TitleLabel.height())  <span class="comment"># 设置按钮高度为标题栏高度</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.clicked.connect(<span class="variable language_">self</span>._changeNormalButton)  <span class="comment"># 按钮信号连接切换到恢复窗口大小按钮函数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_changeNormalButton</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 切换到恢复窗口大小按钮</span></span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            <span class="variable language_">self</span>.showMaximized()  <span class="comment"># 先实现窗口最大化</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setText(<span class="string">b&#x27;\xef\x80\xb2&#x27;</span>.decode(<span class="string">&quot;utf-8&quot;</span>))  <span class="comment"># 更改按钮文本</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setToolTip(<span class="string">&quot;恢复&quot;</span>)  <span class="comment"># 更改按钮提示</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.disconnect()  <span class="comment"># 断开原本的信号槽连接</span></span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.clicked.connect(<span class="variable language_">self</span>._changeMaxButton)  <span class="comment"># 重新连接信号和槽</span></span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_changeMaxButton</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 切换到最大化按钮</span></span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            <span class="variable language_">self</span>.showNormal()</span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setText(<span class="string">b&#x27;\xef\x80\xb1&#x27;</span>.decode(<span class="string">&quot;utf-8&quot;</span>))</span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.setToolTip(<span class="string">&quot;最大化&quot;</span>)</span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.disconnect()</span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.clicked.connect(<span class="variable language_">self</span>._changeNormalButton)</span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">resizeEvent</span>(<span class="params">self, QResizeEvent</span>):</span><br><span class="line">        <span class="comment"># 自定义窗口调整大小事件</span></span><br><span class="line">        <span class="variable language_">self</span>._TitleLabel.setFixedWidth(<span class="variable language_">self</span>.width())  <span class="comment"># 将标题标签始终设为窗口宽度</span></span><br><span class="line">        <span class="comment"># 分别移动三个按钮到正确的位置</span></span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            <span class="variable language_">self</span>._CloseButton.move(<span class="variable language_">self</span>.width() - <span class="variable language_">self</span>._CloseButton.width(), <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            <span class="variable language_">self</span>._MinimumButton.move(<span class="variable language_">self</span>.width() - (<span class="variable language_">self</span>._CloseButton.width() + <span class="number">1</span>) * <span class="number">3</span> + <span class="number">1</span>, <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            <span class="variable language_">self</span>._MaximumButton.move(<span class="variable language_">self</span>.width() - (<span class="variable language_">self</span>._CloseButton.width() + <span class="number">1</span>) * <span class="number">2</span> + <span class="number">1</span>, <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="comment"># 重新调整边界范围以备实现鼠标拖放缩放窗口大小，采用三个列表生成式生成三个列表</span></span><br><span class="line">        <span class="variable language_">self</span>._right_rect = [QPoint(x, y) <span class="keyword">for</span> x <span class="keyword">in</span> <span class="built_in">range</span>(<span class="variable language_">self</span>.width() - <span class="variable language_">self</span>._padding, <span class="variable language_">self</span>.width() + <span class="number">1</span>)</span><br><span class="line">                            <span class="keyword">for</span> y <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, <span class="variable language_">self</span>.height() - <span class="variable language_">self</span>._padding)]</span><br><span class="line">        <span class="variable language_">self</span>._bottom_rect = [QPoint(x, y) <span class="keyword">for</span> x <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, <span class="variable language_">self</span>.width() - <span class="variable language_">self</span>._padding)</span><br><span class="line">                             <span class="keyword">for</span> y <span class="keyword">in</span> <span class="built_in">range</span>(<span class="variable language_">self</span>.height() - <span class="variable language_">self</span>._padding, <span class="variable language_">self</span>.height() + <span class="number">1</span>)]</span><br><span class="line">        <span class="variable language_">self</span>._corner_rect = [QPoint(x, y) <span class="keyword">for</span> x <span class="keyword">in</span> <span class="built_in">range</span>(<span class="variable language_">self</span>.width() - <span class="variable language_">self</span>._padding, <span class="variable language_">self</span>.width() + <span class="number">1</span>)</span><br><span class="line">                             <span class="keyword">for</span> y <span class="keyword">in</span> <span class="built_in">range</span>(<span class="variable language_">self</span>.height() - <span class="variable language_">self</span>._padding, <span class="variable language_">self</span>.height() + <span class="number">1</span>)]</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mousePressEvent</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="comment"># 重写鼠标点击的事件</span></span><br><span class="line">        <span class="keyword">if</span> (event.button() == Qt.LeftButton) <span class="keyword">and</span> (event.pos() <span class="keyword">in</span> <span class="variable language_">self</span>._corner_rect):</span><br><span class="line">            <span class="comment"># 鼠标左键点击右下角边界区域</span></span><br><span class="line">            <span class="variable language_">self</span>._corner_drag = <span class="literal">True</span></span><br><span class="line">            event.accept()</span><br><span class="line">        <span class="keyword">elif</span> (event.button() == Qt.LeftButton) <span class="keyword">and</span> (event.pos() <span class="keyword">in</span> <span class="variable language_">self</span>._right_rect):</span><br><span class="line">            <span class="comment"># 鼠标左键点击右侧边界区域</span></span><br><span class="line">            <span class="variable language_">self</span>._right_drag = <span class="literal">True</span></span><br><span class="line">            event.accept()</span><br><span class="line">        <span class="keyword">elif</span> (event.button() == Qt.LeftButton) <span class="keyword">and</span> (event.pos() <span class="keyword">in</span> <span class="variable language_">self</span>._bottom_rect):</span><br><span class="line">            <span class="comment"># 鼠标左键点击下侧边界区域</span></span><br><span class="line">            <span class="variable language_">self</span>._bottom_drag = <span class="literal">True</span></span><br><span class="line">            event.accept()</span><br><span class="line">        <span class="keyword">elif</span> (event.button() == Qt.LeftButton) <span class="keyword">and</span> (event.y() &lt; <span class="variable language_">self</span>._TitleLabel.height()):</span><br><span class="line">            <span class="comment"># 鼠标左键点击标题栏区域</span></span><br><span class="line">            <span class="variable language_">self</span>._move_drag = <span class="literal">True</span></span><br><span class="line">            <span class="variable language_">self</span>.move_DragPosition = event.globalPos() - <span class="variable language_">self</span>.pos()</span><br><span class="line">            event.accept()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mouseMoveEvent</span>(<span class="params">self, QMouseEvent</span>):</span><br><span class="line">        <span class="comment"># 判断鼠标位置切换鼠标手势</span></span><br><span class="line">        <span class="keyword">if</span> QMouseEvent.pos() <span class="keyword">in</span> <span class="variable language_">self</span>._corner_rect:</span><br><span class="line">            <span class="variable language_">self</span>.setCursor(Qt.SizeFDiagCursor)</span><br><span class="line">        <span class="keyword">elif</span> QMouseEvent.pos() <span class="keyword">in</span> <span class="variable language_">self</span>._bottom_rect:</span><br><span class="line">            <span class="variable language_">self</span>.setCursor(Qt.SizeVerCursor)</span><br><span class="line">        <span class="keyword">elif</span> QMouseEvent.pos() <span class="keyword">in</span> <span class="variable language_">self</span>._right_rect:</span><br><span class="line">            <span class="variable language_">self</span>.setCursor(Qt.SizeHorCursor)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="variable language_">self</span>.setCursor(Qt.ArrowCursor)</span><br><span class="line">        <span class="comment"># 当鼠标左键点击不放及满足点击区域的要求后，分别实现不同的窗口调整</span></span><br><span class="line">        <span class="comment"># 没有定义左方和上方相关的5个方向，主要是因为实现起来不难，但是效果很差，拖放的时候窗口闪烁，再研究研究是否有更好的实现</span></span><br><span class="line">        <span class="keyword">if</span> Qt.LeftButton <span class="keyword">and</span> <span class="variable language_">self</span>._right_drag:</span><br><span class="line">            <span class="comment"># 右侧调整窗口宽度</span></span><br><span class="line">            <span class="variable language_">self</span>.resize(QMouseEvent.pos().x(), <span class="variable language_">self</span>.height())</span><br><span class="line">            QMouseEvent.accept()</span><br><span class="line">        <span class="keyword">elif</span> Qt.LeftButton <span class="keyword">and</span> <span class="variable language_">self</span>._bottom_drag:</span><br><span class="line">            <span class="comment"># 下侧调整窗口高度</span></span><br><span class="line">            <span class="variable language_">self</span>.resize(<span class="variable language_">self</span>.width(), QMouseEvent.pos().y())</span><br><span class="line">            QMouseEvent.accept()</span><br><span class="line">        <span class="keyword">elif</span> Qt.LeftButton <span class="keyword">and</span> <span class="variable language_">self</span>._corner_drag:</span><br><span class="line">            <span class="comment"># 右下角同时调整高度和宽度</span></span><br><span class="line">            <span class="variable language_">self</span>.resize(QMouseEvent.pos().x(), QMouseEvent.pos().y())</span><br><span class="line">            QMouseEvent.accept()</span><br><span class="line">        <span class="keyword">elif</span> Qt.LeftButton <span class="keyword">and</span> <span class="variable language_">self</span>._move_drag:</span><br><span class="line">            <span class="comment"># 标题栏拖放窗口位置</span></span><br><span class="line">            <span class="variable language_">self</span>.move(QMouseEvent.globalPos() - <span class="variable language_">self</span>.move_DragPosition)</span><br><span class="line">            QMouseEvent.accept()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mouseReleaseEvent</span>(<span class="params">self, QMouseEvent</span>):</span><br><span class="line">        <span class="comment"># 鼠标释放后，各扳机复位</span></span><br><span class="line">        <span class="variable language_">self</span>._move_drag = <span class="literal">False</span></span><br><span class="line">        <span class="variable language_">self</span>._corner_drag = <span class="literal">False</span></span><br><span class="line">        <span class="variable language_">self</span>._bottom_drag = <span class="literal">False</span></span><br><span class="line">        <span class="variable language_">self</span>._right_drag = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&quot;__main__&quot;</span>:</span><br><span class="line">    <span class="keyword">from</span> PyQt5.QtWidgets <span class="keyword">import</span> QApplication</span><br><span class="line">    <span class="keyword">import</span> sys</span><br><span class="line"></span><br><span class="line">    app = QApplication(sys.argv)</span><br><span class="line">    <span class="comment"># app.setStyleSheet(open(&quot;./UnFrameStyle.qss&quot;).read())</span></span><br><span class="line">    window = QUnFrameWindow()</span><br><span class="line">    window.setCloseButton(<span class="literal">True</span>)</span><br><span class="line">    window.setMinMaxButtons(<span class="literal">True</span>)</span><br><span class="line">    window.show()</span><br><span class="line">    sys.exit(app.exec_())</span><br></pre></td></tr></table></figure>

<h2 id="第二"><a href="#第二" class="headerlink" title="第二"></a>第二</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> PyQt6.QtCore <span class="keyword">import</span> Qt, QPointF, QPoint</span><br><span class="line"><span class="keyword">from</span> PyQt6.QtWidgets <span class="keyword">import</span> QApplication, QMainWindow, QWidget</span><br><span class="line"> </span><br><span class="line"><span class="keyword">class</span> <span class="title class_">MainWindow</span>(<span class="title class_ inherited__">QMainWindow</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">super</span>().__init__()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 设置窗口无边框</span></span><br><span class="line">        <span class="variable language_">self</span>.setWindowFlags(Qt.WindowType.FramelessWindowHint)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 创建一个子窗口</span></span><br><span class="line">        <span class="variable language_">self</span>.widget = QWidget(<span class="variable language_">self</span>)</span><br><span class="line">        <span class="variable language_">self</span>.widget.setGeometry(<span class="number">0</span>, <span class="number">0</span>, <span class="number">200</span>, <span class="number">200</span>)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 设置子窗口背景颜色</span></span><br><span class="line">        <span class="variable language_">self</span>.widget.setStyleSheet(<span class="string">&quot;background-color: red;&quot;</span>)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 记录鼠标按下时的坐标</span></span><br><span class="line">        <span class="variable language_">self</span>.mouse_pos = <span class="literal">None</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mousePressEvent</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="comment"># 鼠标按下时记录坐标</span></span><br><span class="line">        <span class="variable language_">self</span>.mouse_pos = event.globalPosition()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mouseMoveEvent</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="comment"># 鼠标移动时计算移动距离</span></span><br><span class="line">        <span class="keyword">if</span> <span class="variable language_">self</span>.mouse_pos:</span><br><span class="line">            diff = event.globalPosition() - <span class="variable language_">self</span>.mouse_pos</span><br><span class="line">            <span class="variable language_">self</span>.move(<span class="variable language_">self</span>.pos() + diff.toPoint())</span><br><span class="line">            <span class="variable language_">self</span>.mouse_pos = event.globalPosition()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mouseReleaseEvent</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="comment"># 鼠标释放时清空坐标</span></span><br><span class="line">        <span class="variable language_">self</span>.mouse_pos = <span class="literal">None</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    app = QApplication([])</span><br><span class="line">    window = MainWindow()</span><br><span class="line">    window.show()</span><br><span class="line">    app.<span class="built_in">exec</span>()</span><br></pre></td></tr></table></figure>

<h2 id="第三"><a href="#第三" class="headerlink" title="第三"></a>第三</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"><span class="keyword">from</span> PySide6.QtWidgets <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> PySide6.QtGui <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> PySide6.QtCore <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> ui <span class="keyword">import</span> ui_main_win</span><br><span class="line"> </span><br><span class="line"><span class="comment"># 主窗口</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">main_win</span>(<span class="title class_ inherited__">QWidget</span>):</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self,parent = <span class="literal">None</span></span>):</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 从文件中加载UI定义</span></span><br><span class="line">        <span class="built_in">super</span>(main_win, <span class="variable language_">self</span>).__init__(parent)</span><br><span class="line">        <span class="variable language_">self</span>.ui = ui_main_win.Ui_Form()</span><br><span class="line">        <span class="variable language_">self</span>.ui.setupUi(<span class="variable language_">self</span>)</span><br><span class="line"></span><br><span class="line">        <span class="variable language_">self</span>.setWindowFlag(Qt.FramelessWindowHint)		<span class="comment">#将界面设置为无框</span></span><br><span class="line">        <span class="variable language_">self</span>.setAttribute(Qt.WA_TranslucentBackground)	<span class="comment">#将界面属性设置为半透明</span></span><br><span class="line">        <span class="variable language_">self</span>.shadow = QGraphicsDropShadowEffect()		<span class="comment">#设定一个阴影,半径为 4,颜色为 2, 10, 25,偏移为 0,0</span></span><br><span class="line">        <span class="variable language_">self</span>.shadow.setBlurRadius(<span class="number">4</span>)</span><br><span class="line">        <span class="variable language_">self</span>.shadow.setColor(QColor(<span class="number">2</span>, <span class="number">10</span>, <span class="number">25</span>))</span><br><span class="line">        <span class="variable language_">self</span>.shadow.setOffset(<span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        <span class="variable language_">self</span>.ui.frame.setGraphicsEffect(<span class="variable language_">self</span>.shadow)	<span class="comment">#为frame设定阴影效果</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#   --------------------------------------------------移动功能-------------------------------------------------</span></span><br><span class="line"> </span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mousePressEvent</span>(<span class="params">self, event</span>):		<span class="comment">#鼠标左键按下时获取鼠标坐标</span></span><br><span class="line">        <span class="keyword">if</span> event.button() == Qt.LeftButton:</span><br><span class="line">            <span class="variable language_">self</span>._move_drag = <span class="literal">True</span></span><br><span class="line">            <span class="variable language_">self</span>.cursor_win_pos = event.globalPosition() - <span class="variable language_">self</span>.pos()</span><br><span class="line">            event.accept()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mouseMoveEvent</span>(<span class="params">self, event</span>):	<span class="comment">#鼠标在按下左键的情况下移动时,根据坐标移动界面</span></span><br><span class="line">        <span class="comment"># 移动事件</span></span><br><span class="line">        <span class="keyword">if</span> Qt.LeftButton <span class="keyword">and</span> <span class="variable language_">self</span>._move_drag:</span><br><span class="line">            m_Point = event.globalPosition() - <span class="variable language_">self</span>.cursor_win_pos</span><br><span class="line">            <span class="variable language_">self</span>.move(m_Point.x() ,m_Point.y())</span><br><span class="line">            event.accept()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mouseReleaseEvent</span>(<span class="params">self, event</span>):	<span class="comment">#鼠标按键释放时,取消移动</span></span><br><span class="line">        <span class="variable language_">self</span>._move_drag = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 每一个 PySide6 应用都必须创建一个应用对象</span></span><br><span class="line">app = QApplication([])</span><br><span class="line">main_win = main_win()</span><br><span class="line">main_win.show()</span><br><span class="line">sys.exit(app.<span class="built_in">exec</span>())</span><br></pre></td></tr></table></figure>

<h2 id="第四"><a href="#第四" class="headerlink" title="第四"></a>第四</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"><span class="keyword">from</span> PySide6 <span class="keyword">import</span> QtGui</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> uis.frame_ui <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">import</span> icons_rc</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">MainWindow</span>(<span class="title class_ inherited__">QMainWindow</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">super</span>().__init__()</span><br><span class="line">        <span class="variable language_">self</span>.ui = Ui_MainWindow()</span><br><span class="line">        <span class="variable language_">self</span>.ui.setupUi(<span class="variable language_">self</span>)</span><br><span class="line">        <span class="comment"># 使模拟边框的3个按钮生效(关闭、最小化、最大化、双击标题框)</span></span><br><span class="line">        <span class="variable language_">self</span>.redefine_window_border_btn()</span><br><span class="line">        <span class="comment"># 设置无边框</span></span><br><span class="line">        <span class="variable language_">self</span>.setWindowFlag(Qt.Window | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint</span><br><span class="line">                           | Qt.WindowMinimizeButtonHint| Qt.WindowMaximizeButtonHint)</span><br><span class="line">        <span class="variable language_">self</span>.centralWidget().layout().setContentsMargins(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        <span class="variable language_">self</span>.ui.window_title.setText(<span class="string">&quot;模板窗口V1.0&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">resize_maximize</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        最大化窗口</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">if</span> <span class="variable language_">self</span>.isMaximized():</span><br><span class="line">            <span class="variable language_">self</span>.showNormal()</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="variable language_">self</span>.showMaximized()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">double_clicked_border_bar</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        双击顶部标题条,使其在最大化和还原之间切换</span></span><br><span class="line"><span class="string">        :param event:</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">if</span> event.button() == QtGui.Qt.MouseButton.LeftButton:</span><br><span class="line">            <span class="variable language_">self</span>.resize_maximize()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">move_title_bar</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        拖动顶部标题条</span></span><br><span class="line"><span class="string">        :param event:</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        <span class="variable language_">self</span>.windowHandle().startSystemMove()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">redefine_window_border_btn</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        使模拟边框的3个按钮生效(关闭、最小化、最大化、双击标题框)</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        <span class="variable language_">self</span>.ui.btn_close.clicked.connect(<span class="variable language_">self</span>.close)  <span class="comment"># 关闭按钮</span></span><br><span class="line">        <span class="variable language_">self</span>.ui.btn_min.clicked.connect(<span class="variable language_">self</span>.showMinimized)  <span class="comment"># 最小化按钮</span></span><br><span class="line">        <span class="variable language_">self</span>.ui.btn_max.clicked.connect(<span class="variable language_">self</span>.resize_maximize)  <span class="comment"># 最大化按钮</span></span><br><span class="line">        <span class="comment"># 设置可拖动（通过拖动窗口上的横条来达到拖动窗口的效果）</span></span><br><span class="line">        <span class="variable language_">self</span>.ui.border_frame_mid.mouseDoubleClickEvent = <span class="variable language_">self</span>.double_clicked_border_bar</span><br><span class="line">        <span class="variable language_">self</span>.ui.border_frame_right.mouseDoubleClickEvent = <span class="variable language_">self</span>.double_clicked_border_bar</span><br><span class="line">        <span class="variable language_">self</span>.ui.border_frame_mid.mouseMoveEvent = <span class="variable language_">self</span>.move_title_bar</span><br><span class="line">        <span class="variable language_">self</span>.ui.border_frame_right.mouseMoveEvent = <span class="variable language_">self</span>.move_title_bar</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    app = QApplication(sys.argv)</span><br><span class="line">    window = MainWindow()</span><br><span class="line">    window.show()</span><br><span class="line">    sys.exit(app.<span class="built_in">exec</span>())</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://veryXing.github.io">xing</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://veryxing.github.io/article/0.html">https://veryxing.github.io/article/0.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="https://veryXing.github.io" target="_blank">Xing's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/PyQt/">PyQt</a></div><div class="post-share"><div class="social-share" data-image="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><a class="prev-post pull-left" href="/article/bf8fd827.html" title="QSS (Qt Style Sheet) 样式设定"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-6.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">QSS (Qt Style Sheet) 样式设定</div></div></a><a class="next-post pull-right" href="/article/37bece30.html" title="利用QML实现无边框窗体，要求可移动，可缩放"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-3.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">利用QML实现无边框窗体，要求可移动，可缩放</div></div></a></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a href="/article/2241662d.html" title="PyQt5窗口跟随其它窗口"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-3.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-10-23</div><div class="title">PyQt5窗口跟随其它窗口</div></div></a><a href="/article/32b656da.html" title="PyQt密码管理系统"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-2.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-10-20</div><div class="title">PyQt密码管理系统</div></div></a><a href="/article/f305b1cc.html" title="PyQt属性动画(QPropertyAnimation)"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-4.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-08</div><div class="title">PyQt属性动画(QPropertyAnimation)</div></div></a><a href="/article/bf8fd827.html" title="QSS (Qt Style Sheet) 样式设定"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-6.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-10-14</div><div class="title">QSS (Qt Style Sheet) 样式设定</div></div></a><a href="/article/5a4e93df.html" title="PyQt5动画边框阴影"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-6.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-09-25</div><div class="title">PyQt5动画边框阴影</div></div></a><a href="/article/3217c859.html" title="三种方式绑定信号槽"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-10.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-04</div><div class="title">三种方式绑定信号槽</div></div></a></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info is-center"><div class="avatar-img"><img src= "/images/2.gif" data-lazy-src="/img/butterfly-icon.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">xing</div><div class="author-info-description"></div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">59</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">55</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/veryXing"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#pyqt5-%E6%97%A0%E8%BE%B9%E6%A1%86%E7%95%8C%E9%9D%A2"><span class="toc-number">1.</span> <span class="toc-text">pyqt5 无边框界面</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%BA%8C"><span class="toc-number">2.</span> <span class="toc-text">第二</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%B8%89"><span class="toc-number">3.</span> <span class="toc-text">第三</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E5%9B%9B"><span class="toc-number">4.</span> <span class="toc-text">第四</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/article/18647ffa.html" title="pytest-qt 测试模态窗体."><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="pytest-qt 测试模态窗体."/></a><div class="content"><a class="title" href="/article/18647ffa.html" title="pytest-qt 测试模态窗体.">pytest-qt 测试模态窗体.</a><time datetime="2024-11-27T17:01:35.284Z" title="发表于 2024-11-28 01:01:35">2024-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/5a8a6c8d.html" title="post"><img src= "/images/2.gif" data-lazy-src="http://up.36992.com/pic/e6/c5/51/e6c551e768092c8655292d89a4034a74.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="post"/></a><div class="content"><a class="title" href="/article/5a8a6c8d.html" title="post">post</a><time datetime="2024-10-31T15:27:17.000Z" title="发表于 2024-10-31 23:27:17">2024-10-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/140ab620.html" title="某网站自动下载音乐mp3和歌词"><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-6.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="某网站自动下载音乐mp3和歌词"/></a><div class="content"><a class="title" href="/article/140ab620.html" title="某网站自动下载音乐mp3和歌词">某网站自动下载音乐mp3和歌词</a><time datetime="2024-10-31T12:15:16.000Z" title="发表于 2024-10-31 20:15:16">2024-10-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/32b656da.html" title="PyQt密码管理系统"><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-2.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="PyQt密码管理系统"/></a><div class="content"><a class="title" href="/article/32b656da.html" title="PyQt密码管理系统">PyQt密码管理系统</a><time datetime="2024-10-20T14:36:18.000Z" title="发表于 2024-10-20 22:36:18">2024-10-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/a0a0fd82.html" title="PyQt5实现桌面小宠物"><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="PyQt5实现桌面小宠物"/></a><div class="content"><a class="title" href="/article/a0a0fd82.html" title="PyQt5实现桌面小宠物">PyQt5实现桌面小宠物</a><time datetime="2024-10-20T14:28:05.000Z" title="发表于 2024-10-20 22:28:05">2024-10-20</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2024 By xing</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="true" data-click="false"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>(() => {
  const pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

  window.pjax = new Pjax({
    elements: 'a:not([target="_blank"])',
    selectors: pjaxSelectors,
    cacheBust: false,
    analytics: false,
    scrollRestoration: false
  })

  const triggerPjaxFn = (val) => {
    if (!val) return
    Object.values(val).forEach(fn => fn())
  }

  document.addEventListener('pjax:send', () => {
    // removeEventListener
    btf.removeGlobalFnEvent('pjaxSendOnce')
    btf.removeGlobalFnEvent('themeChange')

    // reset readmode
    const $bodyClassList = document.body.classList
    if ($bodyClassList.contains('read-mode')) $bodyClassList.remove('read-mode')

    triggerPjaxFn(window.globalFn.pjaxSend)
  })

  document.addEventListener('pjax:complete', () => {
    btf.removeGlobalFnEvent('pjaxCompleteOnce')
    document.querySelectorAll('script[data-pjax]').forEach(item => {
      const newScript = document.createElement('script')
      const content = item.text || item.textContent || item.innerHTML || ""
      Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
      newScript.appendChild(document.createTextNode(content))
      item.parentNode.replaceChild(newScript, item)
    })

    triggerPjaxFn(window.globalFn.pjaxComplete)
  })

  document.addEventListener('pjax:error', e => {
    if (e.request.status === 404) {
      pjax.loadUrl('/404.html')
    }
  })
})()</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>